from functools import wraps
from typing import List


def FieldsFilter(fields: List[str]):
    """
    字段过滤
    :param fields: 过滤字段
    :return:
    """

    def decorator(func):
        @wraps(func)
        async def wrapper(*args, **kwargs):

            result = await func(*args, **kwargs)
            if result['total']>0:
                for i in range(result['total']):
                    if isinstance(result['rows'][i], dict):
                        result['rows'][i] = result['rows'][i]
                    else:
                        result['rows'][i] = result['rows'][i].__dict__

                    for field in fields:
                        if result['rows'][i].get(field) is not None:
                            del result['rows'][i][field]
            return result

        return wrapper

    return decorator
